﻿#pragma once
#include "Turtle.h"
#include "Screen.h"

#define IS_STANDING 0
#define IS_MOVING_LEFT 1
#define IS_MOVING_RIGHT 2
#define IS_FLYING 3

class CMario :
	public MObject
{

protected:
	float _maxvx;
	float _maxvy;

	int _level;

	bool _isMoving;
	bool _isJumping;

	bool _allowJump;

	float _lastX;
	float _lastY;

	float _extraVy;

	int _lastDir;


	shared_ptr<Sprite> _spriteStandLeft,_spriteStandRight,_spriteMoveLeft,_spriteMoveRight, _spriteJumpLeft,_spriteJumpRight;
	shared_ptr<Sprite> _spriteStandLeft1,_spriteStandRight1,_spriteMoveLeft1,_spriteMoveRight1, _spriteJumpLeft1,_spriteJumpRight1;
	shared_ptr<Sprite> _spriteStandLeft2,_spriteStandRight2,_spriteMoveLeft2,_spriteMoveRight2, _spriteJumpLeft2,_spriteJumpRight2;
	shared_ptr<Sprite> _spriteStandLeft3,_spriteStandRight3,_spriteMoveLeft3,_spriteMoveRight3, _spriteJumpLeft3,_spriteJumpRight3;

	shared_ptr<Sprite> _spriteDie;

	int _dieDelayTime;

	int _immortalTime;

	int _slideTime;

	int _delayMove;

	int _currentSpriteLevel;

	int _life;

	int _coin;

	int _score;

	Vector _teleport;

	bool _inNewRoom;
	Vector _newRoomPos;

	float _xEndMap;


public:
	CMario(void);
	CMario(float x, float y, int Width, int Height, float vx, float vy, int deltaTime, LPD3DXSPRITE spriteHandler, LPDIRECT3DTEXTURE9 image);
	CMario(float x, float y, float vx, float vy, int deltaTime,int resourceName,CResourceManager *rm);
	CMario(int i);
	~CMario(void);

	void Move();
	void Render();
	void MoveLeft();
	void MoveRight();
	void Jump();
	void fallDown();
	void Stand();
	void checkSpeed();

	void setVelocity(Vector v, shared_ptr<MObject> Object);
	void actAfterCollided(int Direction, shared_ptr<MObject> Object);

	void setStatus(int Status);

	int getMarioStatus();

	int getLevel(){return _level;};
	void setLevel(int level, bool Flash);

	void setSprite(int level);

	RECT getRect();

	int getLastDir(){return _lastDir;};
	
	bool isMoving(){return _vx != 0;};

	bool _isMoveLeft;
	bool _isMoveRight;

	void setAllowJump(bool allowJump){ _allowJump = allowJump;};
	bool getAllowJump(){return _allowJump;};

	void setLife(int life){_life = life;};
	void setCoin(int coin){_coin = coin;};
	void setScore(int score){_score = score;};

	int getLife(){return _life;};
	int getScore(){return _score;};
	int getCoin(){return _coin;};

	void Teleport(int x, int y){_x = x; _y = y;};
	void setTeleport(int x, int y){_teleport = Vector(x,y);};

	//để biết là Mario đang chui zô hầm
	void setInNewRoom(bool isInNewRoom) {_inNewRoom = isInNewRoom;};
	void setNewRoomPos(Vector v) {_newRoomPos = v;};

	//điểm kết thúc map
	void setXEndMap(float x){ _xEndMap = x;};

public:
	static const int STATUS_ALIVE = 0;
	static const int STATUS_DEAD = -1;
	static const int STATUS_DYING = -2;
	static const int STATUS_CHANGINGLEVEL = 1;
	static const int STATUS_TOPIPE = 2;
	static const int STATUS_OUTPIPE = 3;
	static const int STATUS_MOVENEXTMAP = 4;

	static const int DIR_LEFT = -100;
	static const int DIR_RIGHT = 100;

};